﻿using System;
using DevExpress.XtraEditors;
using MDK.Common;
using MDK.Model.Models;
using MDK.Service;

namespace MDK.Winform
{
    public partial class ucATMControl : XtraUserControl
    {

        public ucATMControl()
        {
            InitializeComponent();
        }

        private void ShowWait(T_Handover info)
        {
            frmWait frm = new frmWait(info);
            frm.ShowDialog();
        }
        /// <summary>
        /// 交接
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnHandOver_Click(object sender, EventArgs e)
        {
            try
            {
                T_Handover info = new T_Handover
                {
                    Id = Guid.NewGuid().ToString("N"),
                    IsNeedCentrifuge = ckC.Checked,
                    IsBloodSample = ckBloodSample.Checked,
                    SendPerson = App.currentUser.RealName,
                    HandTime = DateTime.Now,
                };
                if (WebAPIHelper.Post<T_Handover>("Handover/Add", info))
                {
                    string url = WebApiProxyHelper.StructureUrl(App.systemSetting["FrontWebApiProxyAddress"], App.systemSetting["FrontWebApiProxyPort"], "Handover/BeginHandover");
                    //开始交接
                    if (WebApiProxyHelper.Post<BeginHandoverRequest>(url, new BeginHandoverRequest() { handoverId = info.Id, needCentrifuge = info.IsNeedCentrifuge.Value, priority = info.IsBloodSample.Value }))
                    {
                        ShowWait(info);
                    }
                }
            }
            catch
            {
                FastMessageBox.Error("确认预处理程序是否启动");
            }
        }
    }
}
